package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.service.ISetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 套餐 前端控制器
 * </p>
 *
 * @author 
 * @since 2024-05-22
 */
@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    public ISetmealService setmealService;

    /**
     * 新增套餐
     * @param setmealDto
     * @return
     */
    @PostMapping
    public R<String> saveSeatmeal(@RequestBody SetmealDto setmealDto){
        return setmealService.saveSeatmeal(setmealDto);
    }

    /**
     * 分页查询套餐
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page> pageQuery(Integer page,Integer pageSize,String name){
        return setmealService.pageQuery(page,pageSize,name);
    }

    /**
     * 根据套餐id查询套餐记录进行回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<SetmealDto> queryByid(@PathVariable Long id){
        return setmealService.queryByid(id);
    }

    @PostMapping("/status/{status}")
    public R<String> updateStatus(@PathVariable Integer status,@RequestParam(name = "ids") Long[] id){
        log.info("传入的状态:{},传入的id:{}",status,id.toString());
        return setmealService.updateStatus(status,id);
    }

    @DeleteMapping
    public R<String> deleteSetmealById(@RequestParam(name = "ids") List<Long> id){
        log.info("传入的集合为id:{}",id.toString());
        return setmealService.deleteSetmealById(id);
    }

    @GetMapping("/list")
    public R<List<Setmeal>> getSetmealList(Setmeal setmeal){
        return setmealService.getSetmealList(setmeal);
    }


    @PutMapping()
    public R<String> editSetmeal(@RequestBody Setmeal setmeal){
        setmealService.saveOrUpdate(setmeal);
        return R.success("修改成功");
    }
}
